package com.example.demo.controller;

import com.example.demo.entity.EnvParams;
import com.example.demo.entity.ResponseInfo;
import com.example.demo.service.EnvParamsService;
import com.example.demo.utils.PageInfoNew;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/envParams")
@Api(tags = "环境变量参数管理")
public class EnvParamsController {
    @Resource
    EnvParamsService envParamsService;

    @PostMapping("/add")
    @ApiOperation(value = "环境变量参数添加接口")
    public ResponseInfo<String> add(@RequestBody EnvParams envParams) {
        envParamsService.insert(envParams);
        return ResponseInfo.successInfo("");
    }

    @PostMapping("update")
    @ApiOperation(value = "环境变量参数更新接口")
    public ResponseInfo<String> update(@RequestBody EnvParams envParams) {
        envParamsService.update(envParams);
        return ResponseInfo.successInfo("");
    }

    @GetMapping("/details")
    @ApiOperation(value = "获取环境变量参数详情接口")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int")
    public ResponseInfo<EnvParams> getApiDetails(@RequestParam int id) {
        return ResponseInfo.successInfo(envParamsService.selectOne(id));
    }

    @GetMapping("/page")
    @ApiOperation(value = "环境变量参数分页接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页长度", required = true, dataType = "int"),
            @ApiImplicitParam(name = "projectId", value = "项目id", required = true, dataType = "int")
    })
    public ResponseInfo<PageInfoNew<EnvParams>> page(@RequestParam int pageNum,
                                                     @RequestParam int pageSize,
                                                     @RequestParam Integer projectId) {
        return ResponseInfo.successInfo(envParamsService.selectByProjectId(pageNum, pageSize, projectId));
    }
}
